import { axios } from '@/utils/request'

const api = {
  manager: '/managers',
  role: '/roles',
  courier_company: '/courier_companies',
  banner: '/banners'
}

export function getManagerList (parameter) {
  return axios({
    url: api.manager,
    method: 'get',
    params: parameter
  })
}

export function saveManager (parameter) {
  return axios({
    url: api.manager,
    method: parameter.hasOwnProperty('id') ? 'patch' : 'post',
    params: parameter
  })
}

export function getRoleList (parameter) {
  return axios({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function saveRole (parameter) {
  return axios({
    url: api.role + (parameter.hasOwnProperty('id') ? '/' + parameter.id : ''),
    method: parameter.hasOwnProperty('id') ? 'patch' : 'post',
    params: parameter
  })
}

export function getRoleInfo (parameter) {
  return axios({
    url: api.role + '/' + parameter.id,
    method: 'get'
  })
}

export function getCourierCompanyList (params) {
  return axios({
    url: api.courier_company,
    method: 'get',
    params
  })
}

export function saveCourierCompany (params) {
  return axios({
    url: api.courier_company + (params.hasOwnProperty('id') ? '/' + params.id : ''),
    method: params.hasOwnProperty('id') ? 'patch' : 'post',
    params
  })
}

export function deleteCourierCompany (id) {
  return axios({
    url: api.courier_company + '/' + id,
    method: 'delete'
  })
}

export function getBannerList (params) {
  return axios({
    url: api.banner,
    method: 'get',
    params
  })
}

export function saveBanner (data) {
  return axios({
    url: api.banner + (data.hasOwnProperty('id') ? '/' + data.id : ''),
    method: data.hasOwnProperty('id') ? 'patch' : 'post',
    data
  })
}

export function deleteBanner (id) {
  return axios({
    url: api.banner + '/' + id,
    method: 'delete'
  })
}
